#include<stdio.h>

int main(void)
{
	int birthyear,birthmonth,birthday,place,sex;
	int n;
	scanf("%d",&n);
	
	for(int i=0;i<n;i++)
	{
		scanf("%6d%4d%2d%2d%4d",&place,&birthyear,&birthmonth,&birthday,&sex);
		printf("%4d-%02d-%02d\n",birthyear,birthmonth,birthday);
	}
	
	return 0;
}
/*#include<stdio.h>

int main(void)
{
	char IDnumber[20],rubbish;
	int n;
	scanf("%d",&n);
	getchar();
	
	for(int i=0;i<n;i++)
	{
		for(int i=0;i<18;i++)
		{
			scanf("%c",&IDnumber[i]);
		}
		printf("%c%c%c%c-%c%c-%c%c\n",IDnumber[6],IDnumber[7],IDnumber[8],IDnumber[9],IDnumber[10],IDnumber[11],IDnumber[12],IDnumber[13]);
		getchar();
	}
	
	return 0;
}*/
